<%@ page language="java" import="java.util.*"  pageEncoding="utf-8"%>
<%@include file="common/tag.jsp"%>
<c:set var="CTX" value="${pageContext.request.contextPath}" />
<%@include file="common/indexhead.jsp"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
    
    <title>生产计划单新增页</title>
    </head>

 <body>
<div class="panel panel-primary">
	<div class="panel-heading">
		<div>
			<h3 class="panel-title">生产计划单新增页</h3>
		</div>
		<div class="button"
			style="float: right;margin-top: -27px;margin-right: 5px;">
			<a class="btn btn-info" href="#" onclick="javascript:window.close();"><i class="fa fa-sign-out"></i>退出</a>
		</div>
		<div class="button"
			style="float: right;margin-top: -27px;margin-right: 5px;">
			<div class="btn btn-info"   onclick="tijiao()" href=""><i class="fa fa-check"></i>保存</div>
		</div>
	</div>
	<div class="panel-body" style="height:87%">
			
			
			<form action="/productionplan/adddo" method="post"  id="productionplanadd"  class="form-horizontal"
			style="width:95%;margin-top: 50px;">
			<fieldset>
			<table class="table table-bordered">
				<div class="form-group">
					<label class="col-sm-1 control-label">单据编号</label>
					<div class="col-sm-3">
						<input readOnly=true class="form-control" id="productionPlanDjbh" name="productionPlanDjbh" type="text"
						placeholder = "${number}" value = "${number}"/>
					</div>
					<label class="col-sm-1 control-label">订单编号</label>
					<div class="col-sm-3">
						<input readOnly=true style="width:55%;display: inline-block;" class="form-control" id="productionPlanDdbh" name="productionPlanDdbh" type="text"/>
						<input style="display:none" class="form-control" id="productionPlanDdbhId" name="productionPlanDdbhId" type="text"/>
						<a class="btn btn-info"  onclick="showdialog_dhd();"><i class="fa fa-sign-out"></i>订货单</a>
					</div>
					<label class="col-sm-1 control-label">货品编码</label>
					<div class="col-sm-3">
						<input readOnly=true style="width:55%;display: inline-block;" class="form-control" id="goodsinformationNumber" name="goodsinformationNumber" type="text"/>
						<input style="display:none" class="form-control" id="productionPlangoodsId" name="productionPlangoodsId" type="text"/>
						<input style="display:none" class="form-control" id="productstructurelistId" name="productstructurelistId" type="text"/>
						<a class="btn btn-info"  onclick="checkhpxx(this);"><i class="fa fa-sign-out"></i>选择货品</a>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-1 control-label">货品名称</label>
					<div class="col-sm-3">
						<input readOnly=true style="display: inline-block;" class="form-control" id="goodsinformationHpmc" name="goodsinformationHpmc" type="text"/>
					</div>
					<label class="col-sm-1 control-label">规格型号</label>
					<div class="col-sm-3">
						<input readOnly=true class="form-control" id="goodsinformationHpxh" name="goodsinformationHpxh" type="text"/>
					</div>
					<label class="col-sm-1 control-label">数量</label>
					<div class="col-sm-3">
						<input class="form-control" id="productionPlanSl" name="productionPlanSl" type="text"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-1 control-label">单据日期</label>
					<div class="col-sm-3">
						<input readOnly=true class="form-control mydate" id="productionPlanDjrq" name="productionPlanDjrq" type="text"/>
					</div>
					<label class="col-sm-1 control-label">计划开工日</label>
					<div class="col-sm-3">
						<input readOnly=true class="form-control mydate" id="productionPlanJhkgrq" name="productionPlanJhkgrq" type="text"/>
					</div>
					<label class="col-sm-1 control-label">计划完工日</label>
					<div class="col-sm-3">
						<input readOnly=true class="form-control mydate" id="productionPlanJhwgrq" name="productionPlanJhwgrq" type="text"/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-1 control-label">备注</label>
					<div class="col-sm-11">
						<input class="form-control" id="productionPlanBz" name="productionPlanBz" type="text"/>
					</div>
				</div>
				</table>
			</fieldset>
			<hr></hr>
<table class="table table-bordered">
  <caption style="width:90%">领料明细
  <p style="float:right;width:50%;text-align:right">
  <a style="display:none"  onclick="addTable();" class="btn btn-info">增加商品</a>
  <a  style="display:none" onclick="del();" class="btn btn-danger">批量删除</a>
  </p></caption>
  <thead>
    <tr>
	 <!--  <th style="width:3%" rowspan="2"><input type='checkbox'  id='checkAll' onclick="checkAll_f()" value='New'></th> -->
      <th>序号</th>
      <th>材料编号</th>
      <th>材料名称</th>
      <th>型号规格</th>
      <th>计量单位</th>
      <th>数量</th>
      <th>金额</th>
      <!-- <th rowspan="2">操作</th> -->
    </tr>
  </thead>
  <tbody id="addTable">
  </tbody>
</table>
		</form>
		<hr></hr>
		
			<style>
.table >thead> tr> th{
	text-align:center;
	vertical-align: middle;
	background-color: #DDD9D4;
	border-color:#BEC2C1;
	padding-left: 0px;
}
.table >tbody> tr> td>input{
	width:100%;
}
.table >tbody> tr> td {
	text-align:center;
	width:8%
}
</style>

	</div>
</div>
<%@include file="common/indexbottom.jsp"%>
<div id="deptdialog">
	<%@include file="checkgoodsforscjhd.jsp" %>
</div>
<div id="deptdialogforthis">
	<%@include file="checkSalesOrder.jsp" %>
</div>
<!-- 弹出框重写 -->
<div id="ycf-alert" class="modal">
      <div class="modal-dialog modal-sm">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
            <h5 class="modal-title"><i class="fa fa-exclamation-circle"></i> [Title]</h5>
          </div>
          <div class="modal-body small">
            <p>[Message]</p>
          </div>
          <div class="modal-footer" >
            <button type="button" class="btn btn-primary ok" data-dismiss="modal">[BtnOk]</button>
            <button type="button" class="btn btn-default cancel" data-dismiss="modal">[BtnCancel]</button>
          </div>
        </div>
      </div>
    </div>
<!-- 弹出框重写end -->
<script type="text/javascript">
var count=0;

function showdialog_dhd(url){
	//$("#deptdialog").html('<iframe src="' + url + '" frameborder="0" height="100%" width="100%" id="dialogFrame" scrolling="auto"></iframe>');
	$("#deptdialogforthis").dialog("open");
}

fenye(${pb.currentPage},${pb.totalPages},${pb.totalRecords},${pb.pagesize},yongan.URL.salesOrderList());

function checkhpxx(obj){
	$("#deptdialog").dialog("open");
}

function getValue(id){
	$.ajax({
        type: "get",
        url: "/productionplan/"+id+"/value",
        dataType: "json",
       //	contentType: 'application/json;charset=utf-8',
        data: "",
        success: function(data) {
            if (data['success']) {
                setValue(data.data);
            }else{
            	alert("操作失败！该商品没有结构清单");
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
            alert(textStatus);
            alert(errorThrown);
        }
    });
}
function setValue(data){
	$("#productstructurelistId").val(data.productStructureListId);
	$("#goodsinformationHpmc").val(data.goodsinformation.goodsinformationHpmc);
	$("#goodsinformationHpxh").val(data.goodsinformation.goodsinformationHpxh);
	count = parseInt(data.details.length);
	var table1 = $("#addTable");
	table1.empty();
	for(var i=0;i<data.details.length;i++){
		var row = $("<tr></tr>");
		var salesOrderDetailsCksl="";
		//alert(data.details[i].purchasegoodsdetailsRksl)
		if(data.details[i].salesOrderDetailsCksl==null | data.details[i].salesOrderDetailsCksl==""){
			salesOrderDetailsCksl = "";
		}else{
			salesOrderDetailsCksl = data.details[i].salesOrderDetailsCksl;
		}
		row.append("<td style='display:none'><input class='form-control' value='"+data.details[i].detailsId+"' type='text' name='details["+i+"].detailsId' ></td>");
		row.append("<td>"+(i+1)+"</td>");
		row.append("<td>"+data.details[i].goodsinformation.goodsinformationNumber+"</td>");
		row.append("<td>"+data.details[i].goodsinformation.goodsinformationHpmc+"</td>");
		row.append("<td>"+data.details[i].goodsinformation.goodsinformationHpxh+"</td>");
		row.append("<td>"+data.details[i].goodsinformation.goodsinformationHpdw+"</td>");
		row.append("<td>"+data.details[i].detailsSl+"</td>");
		row.append("<td>"+data.details[i].detailsJe+"</td>");
		table1.append(row); 
	}
}



$(function() {
$("#deptdialogforthis").dialog({
		autoOpen : false,   // 是否自动弹出窗口
		modal : true,    // 设置为模态对话框
		resizable : true,
		width : 810,   //弹出框宽度
		height : 440,   //弹出框高度
		title : "选择订货单",  //弹出框标题
		position : "center",  //窗口显示的位置
		buttons:{
			'确定':function(){
				var checked = $("input[type='radio'][name='rd']"); 
				$(checked).each(function(){ 
					if($(this).prop('checked')){ //注意：此处判断不能用$(this).attr("checked")==‘true'来判断。 
						//alert($(this).parent().next().next().html()); 
						$("#productionPlanDdbhId").val($(this).parent().next().html());
						$("#productionPlanDdbh").val($(this).parent().next().next().html());
						//getValue($(this).parent().next().html());
					} 
				});
				$(this).dialog("close");
			},
			'取消':function(){
			$(this).dialog("close");
			}
		}
	});
$("#deptdialog").dialog({
		autoOpen : false,   // 是否自动弹出窗口
		modal : true,    // 设置为模态对话框
		resizable : true,
		width : 810,   //弹出框宽度
		height : 440,   //弹出框高度
		title : "选择货品",  //弹出框标题
		position : "center",  //窗口显示的位置
		buttons:{
			'确定':function(){
				var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
				if(treeObj.getCheckedNodes().length!=0){
					var checkId = treeObj.getCheckedNodes()[0];
					yongan.dialog.addhpxx(checkId);
					$("#goodsinformationNumber").val(checkId.id);
					$("#productionPlangoodsId").val(checkId.rid);
					getValue(checkId.rid);
				}else{
					alert("请选择货品信息！");
				}
				$(this).dialog("close");
			},
			'取消':function(){
			$(this).dialog("close");
			}
		}
	});
$(".mydate").datepicker();
window.Modal = function() {
    var reg = new RegExp("\\[([^\\[\\]]*?)\\]", 'igm');
    var alr = $("#ycf-alert");
    var ahtml = alr.html();
    
    var _alert = function(options) {
        alr.html(ahtml); // 复原
        alr.find('.ok').removeClass('btn-success').addClass('btn-primary');
        alr.find('.cancel').hide();
        _dialog(options);

        return {
            on: function(callback) {
                if (callback && callback instanceof Function) {
                    alr.find('.ok').click(function() {
                        callback(true)
                    });
                }
            }
        };
    };

    var _confirm = function(options) {
        alr.html(ahtml); // 复原
        alr.find('.ok').removeClass('btn-primary').addClass('btn-success');
        alr.find('.cancel').show();
        _dialog(options);

        return {
            on: function(callback) {
                if (callback && callback instanceof Function) {
                    alr.find('.ok').click(function() {
                        callback(true)
                    });

                }
            }
        };
    };

    var _dialog = function(options) {
        var ops = {
            msg: "提示内容",
            title: "操作提示",
            btnok: "确定",
            btncl: "取消"
        };

        $.extend(ops, options);

        console.log(alr);

        var html = alr.html().replace(reg,
        function(node, key) {
            return {
                Title: ops.title,
                Message: ops.msg,
                BtnOk: ops.btnok,
                BtnCancel: ops.btncl
            } [key];
        });

        alr.html(html);
        alr.modal({
            width: 500,
            backdrop: 'static'
        });
    }

    return {
        alert: _alert,
        confirm: _confirm
    }

} ();
});
 
function tijiao() {
Modal.confirm({
    msg: "是否新增？"
}).on(function(e) {
	//var allOutSourcingIn = $("input[id^='count']");
	var json = "{";
	json=json+"'productionPlanDjbh':'"+$("#productionPlanDjbh").val()+"',";
	json=json+"'productionPlanDdbh':'"+$("#productionPlanDdbh").val()+"',";
	json=json+"'productionPlanDdbhId':'"+$("#productionPlanDdbhId").val()+"',";
	json=json+"'productionPlangoodsId':'"+$("#productionPlangoodsId").val()+"',";
	json=json+"'productionPlanSl':'"+$("#productionPlanSl").val()+"',";
	json=json+"'productionPlanDjrq':'"+$("#productionPlanDjrq").val()+"',";
	json=json+"'productionPlanJhkgrq':'"+$("#productionPlanJhkgrq").val()+"',";
	json=json+"'productionPlanJhwgrq':'"+$("#productionPlanJhwgrq").val()+"',";
	json=json+"'productstructurelistId':'"+$("#productstructurelistId").val()+"',";
	json=json+"'productionPlanBz':'"+$("#productionPlanBz").val()+"'";
	json=json+"}";
	console.log(json);
	//var a="{'details[0].ingooddetailsNumber':'q','details[0].ingooddetailsHpmc':'w','details[0].ingooddetailsGgxh':'e','details[0].ingooddetailsDw':'r','details[0].ingooddetailsSl':'t','details[0].ingooddetailsRksl':'y','details[0].ingooddetailsDj':'u','details[0].ingooddetailsZje':'i','details[0].ingooddetailsBz':'o','details[0].ingooddetailsDhrq':'06/28/2018','outsourcinginRkdn': '111'}";
	
	var b=eval('(' + json+ ')');
	//console.log(b);
	//console.log(eval('(' + a+ ')'));
    $.ajax({
        type: "post",
        url: yongan.URL.productionplanAdd(),
        dataType: "json",
       //	contentType: 'application/json;charset=utf-8',
        data: b,
        success: function(data) {
            if (data['success']) {
                Modal.alert({
                    msg: data['data']['stateinfo'],
                    title: '执行结果',
                    btnok: '确定',
                    btncl: '取消'
                }).on(function(e) {
                    window.close();
                });
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest);
            alert(textStatus);
            alert(errorThrown);
        }
    });
});
}
</script>
  </body>
</html>